#ifndef SSD_GLOBAL_H
#define SSD_GLOBAL_H
#include "List.h"
#include "type.h"
#include "fast.h"
#include "dftl.h"
#include "pagemap.h"
#include "flash.h"


#define READ_DELAY        (0.1309/4)
#define WRITE_DELAY       (0.4059/4)
#define ERASE_DELAY       1.5 
#define GC_READ_DELAY  READ_DELAY    // gc read_delay = read delay    
#define GC_WRITE_DELAY WRITE_DELAY  // gc write_delay = write delay 

#define OOB_READ_DELAY    0.0
#define OOB_WRITE_DELAY   0.0

#define CACHE_MAX_ENTRIES 300
#define PRE_THRESHOLD 2         //预取判断阈值
#define NUM_ENTRIES_PER_TIME 8  //预取窗大小

#define PAGE_READ     0
#define PAGE_WRITE    1
#define OOB_READ      2
#define OOB_WRITE     3
#define BLOCK_ERASE   4
#define GC_PAGE_READ  5
#define GC_PAGE_WRITE 6

extern int write_count;
extern int read_count;

extern int flash_read_num;
extern int flash_write_num;
extern int flash_gc_read_num;
extern int flash_gc_write_num;
extern int flash_erase_num;
extern int flash_oob_read_num;
extern int flash_oob_write_num;

extern int map_flash_read_num;
extern int map_flash_write_num;
extern int map_flash_gc_read_num;
extern int map_flash_gc_write_num;
extern int map_flash_erase_num;
extern int map_flash_oob_read_num;
extern int map_flash_oob_write_num;
extern int total_util_sect_num; 
extern int total_extra_sect_num;

/****************************************
 * add by ymb
 ****************************************/
extern int rqst_cnt;
extern int translation_read_num;
extern int translation_write_num;
extern int cache_cmt_hit;
extern int cache_scmt_hit;
extern int cache_slcmt_hit;

/***********************************************************************
 Mapping table
***********************************************************************/
extern int real_min;
extern int real_max;

/***********************************************************************
 Cache
***********************************************************************/
extern int cache_min;
extern int cache_max;

/***********************************************************************
 *    author: ymb    部分常用变量
 ***********************************************************************/
extern int init_flag;

extern int MAP_REAL_MAX_ENTRIES;
extern int MAP_GHOST_MAX_ENTRIES;
extern int MAP_SEQ_MAX_ENTRIES; 
extern int MAP_SECOND_MAX_ENTRIES; 
extern int cache_arr[CACHE_MAX_ENTRIES];
extern int *real_arr;
extern int *ghost_arr;
extern int *second_arr;
extern int *seq_arr;
extern int *entry_arr;
extern int operation_time;

extern struct ftl_operation * ftl_op;
extern int page_num_for_2nd_map_table;

void reset_hit_stat();
void reset_flash_stat();
void find_real_max();
void find_real_min();
int search_table(int *arr, int size, int val);
int find_free_pos( int *arr, int size);
int find_min_ghost_entry();
void find_min_cache();
double callFsim(unsigned int secno, int scount, int operation);
int not_in_cache(unsigned int pageno);
void send_flash_request(int start_blk_no, int block_cnt, int operation, int mapdir_flag);


#endif